var express = require('express');
var router = express.Router();
var { recordModel } =require("../model/searchmodel")
/* GET home page. */
router.get('/record', async function(req, res, next) {
 let data = await recordModel.find()
 console.log(data);
 res.send({
    code:200,
    data
 })
});

router.put('/add/:value', async function(req, res, next) {
    let name = req.params.value
    console.log(req.params.value);
    let data = await recordModel.find({name:name})
   //  console.log(data);
    if(data.length !=0){
        // await recordModel.updateOne({name:name},{$set:{num:data[0].num+1}})
        await recordModel.deleteOne({name:name})
        await recordModel.create({name:name,num:data[0].num+1})
    }else{
        await recordModel.create({name:name,num:1})
    }
    res.send({
       code:200,
    })
   });
router.delete('/delAll', async function(req, res, next) {
    let data = await recordModel.deleteMany({})
   //  console.log(data);
    res.send({
       code:200,
    })
   });
module.exports = router;